<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>初始vue</title>
    <script type="text/javascript"  src="../js/vue.js"></script>
  
</head>

<!-- v-for指令:
1.用于展示列表数据
2.语法: v-for="(item， index) in xxx” :key="yyy"
3.可遍历: 数组、对象、字符串 (用的很少) 、指定次数 (用的很少) -->
<body>
    <div id="root">
        <button @click.once="add">点击添加一个老刘</button>
       <ul>
        <li v-for="(p,index) in persons" :key="p.id">
            {{p.name}} - {{p.age}} - {{index}}
            <input type="text">
        </li>
       </ul>
       <ul>
       
     </div>
</body>

<script type="text/javascript">
   Vue.config.productionTip=false;
   let vm =new Vue({
        el:"#root",
        data:{
            persons: [{
                id:1,
                name:'张三',
                age: 18
            },{
                id:2,
                name:'李四',
                age: 19
            },{
                id:3,
                name:'王五',
                age: 20
            },]
        },
        methods: {
            add(){
                const p ={ id:4,name:'老刘', age: 89}
                this.persons.unshift(p);
            }
        },
    })
    
</script>
</html>